package service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.MonthCallTimeDao;
import dao.impl.MonthCallTimeDaoImpl;
import domain.MonthCallTime;
import domain.User;

import java.util.List;

public class MonthCallTimeService {
    String valueAsString = null;

    private MonthCallTimeDao contacts = new MonthCallTimeDaoImpl();

    //用户每月通话时长统计
    public String ToJson4(User user) {
        String telephone = user.getTelephone();
        int year = user.getYear();
        List<MonthCallTime> list = contacts.SelectMonthCallTimeByTelephone(telephone,year);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            valueAsString = objectMapper.writeValueAsString(list);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return valueAsString;
    }
}
